cmake_minimum_required(VERSION 3.16)

project(Chat_Application VERSION 0.1 LANGUAGES CXX)

set(DCMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Gui Widgets Network)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui Widgets Network)

set(PROJECT_SOURCES
    main.cpp
    hollow_button.cpp
    httpmgr.cpp
    input_box.cpp
    login_button.cpp
    login_form.cpp
    other_login_buttons.cpp
    registration_form.cpp
    responsive_form.cpp
    scroll_bar.cpp
    transparent_transition_interface.cpp
    global.h
    hollow_button.h
    httpmgr.h
    input_box.h
    login_button.h
    login_form.h
    other_login_buttons.h
    registration_form.h
    responsive_form.h
    scroll_bar.h
    singleton.h
    transparent_transition_interface.h
    src.qrc
        global.cpp
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(Chat_Application
        ${PROJECT_SOURCES}
    )
else()
    add_executable(Chat_Application
        ${PROJECT_SOURCES}
    )
endif()

set_target_properties(Chat_Application PROPERTIES
    WIN32_EXECUTABLE TRUE
    MACOSX_BUNDLE FALSE
)

target_link_libraries(Chat_Application PRIVATE
    Qt${QT_VERSION_MAJOR}::Core
    Qt${QT_VERSION_MAJOR}::Gui
    Qt${QT_VERSION_MAJOR}::Widgets
    Qt${QT_VERSION_MAJOR}::Network
)

if(WIN32)
    set(CONFIG_INI "${CMAKE_SOURCE_DIR}/config.ini")
    if(EXISTS "${CONFIG_INI}")
        add_custom_command(TARGET Chat_Application POST_BUILD
            COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CONFIG_INI}" "$<TARGET_FILE_DIR:Chat_Application>/config.ini"
            COMMENT "Copying config.ini to output directory"
        )
    else()
        message(WARNING "config.ini not found at ${CONFIG_INI}; skipping copy step.")
    endif()
endif()

include(GNUInstallDirs)
install(TARGETS Chat_Application
    BUNDLE DESTINATION .
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
